new Vue({
  el: "#app",
  data() {
    return {
      a: {},
      ye: 1, //绑定初始页数
      Total: 0, //绑定初始条数
      loading: false,
      restaurants: [],
      state: "",
      timeout: null,
      data: [],
      defaultProps: {
        children: "children",
        label: "label",
      },
      UserID: decodeURI($.cookie("use")),
      form: {
        SQLSerialNumber: "P_business_article_info",
        PaginationNumber: 1, //页数
        RowAmount: 10, //每页数据条数
        Condition: "",
        ExtensionCondition: "",
        Article_Name: "",
        Brand_SerialNumber: "",
        Shelf: "",
        Supplier_Name: "",
      },
      total: 0,
      count: 0,
      tableData: [],
      // loading: false,
      dialogVisible: false,
      Article_SerialNumber: "",
      // multipleSelection: [],
    };
  },
  mounted() {
    // this.restaurants = this.loadAll();
    // this.getList(); //前端分页
    this.ArticleTree();
  },

  methods: {
    //点击页数方法
    handleCurrentChange(res) {
      this.loading = true;
      this.a.PageNubmer = res;
      this.a.RowAmount = 6;
      console.log(this.a);
      this.qysp(this.a);
    },
    ArticleTree() {
      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        type: "get",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/getFarmerAreaTree",
        // url: "http://192.168.10.66:8083/clientOperation/getFarmerAreaTree",
        data: {},
        success: function (Result) {
          console.log(Result);
          _this.data = Result;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    qysp(res) {
      console.log(res);
      const _this = this;
      // return;
      $.ajax({
        // headers: requestHeaders(),
        url: "https://service.kdddy.cn/donghui/clientOperation/getFarmerListByArea",
        // url: "http://192.168.10.66:8083/clientOperation/getFarmerListByArea",
        type: "get",
        data: res,
        success: function (Result) {
          _this.loading = false;
          console.log(Result);
          // _this.$set(_this.tableData, 0, Result);
          _this.tableData = Result.Rows;
          _this.Total = Result.Total;
          // _this.tableData = Result;
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // loadAll() {
    //   const _this = this;
    //   let Enterprise = new Object();
    //   $.ajax({
    //     headers: requestHeaders(),
    //     type: "get",
    //     // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
    //     url: "https://service.kdddy.cn/donghuiForRequest/Purchase/GetAll",
    //     data: {
    //       pageSize: 15,
    //       pageNumber: 1,
    //     },
    //     success: function (Result) {
    //       console.log(Result, "loadAll");
    //       for (let index = 0; index < Result.Data.length; index++) {
    //         Enterprise = Result.Data[index].Enterprise_Name;
    //       }
    //       // Enterprise_Name = Result.Data;
    //       //   that.total = Result.TotalRows;
    //     },
    //     complete: function (XMLHttpRequest) {
    //       //   requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   console.log(Enterprise);
    //   return Enterprise;
    // },
    querySearchAsync(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString
        ? restaurants.filter(this.createStateFilter(queryString))
        : restaurants;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 3000 * Math.random());
    },
    //value替代
    createStateFilter(queryString) {
      return (state) => {
        return (
          state.Enterprise_Name.toLowerCase().indexOf(
            queryString.toLowerCase()
          ) === 0
        );
      };
    },
    handleSelect(item) {
      console.log(item);
    },
    handleNodeClick(data) {
      this.a = data;
      this.a.RowAmount = 6;

      data.PageNubmer = this.ye;
      data.RowAmount = 6;
      console.log(data);
      this.loading = true;
      this.qysp(data);
    },
    handleEdit(index, row) {
      //#99
      let Article_SerialNumber = sessionStorage.setItem(
        "Article_SerialNumber",
        row.Article_SerialNumber
      );

      window.location.href = "./edit2.html";
      console.log(index, row);
    },
    //#100
    handleDelete(index, row) {
      const _this = this;
      console.log(index, row);
      row.Row_Status = "1";
      console.log(row);
      delete row.Operation_Datetime;
      delete row.Operation_Datetime_Original;
      delete row.Operation_ID;
      delete row.Operation_ID_Original;
      let lArray = new Array();
      lArray.push(row);
      let lJSONObject_business_article_info = new Object();
      lJSONObject_business_article_info.business_article_info = lArray; //换表
      let lJSONObject_DataSet = new Object();
      lJSONObject_DataSet.Modify = lJSONObject_business_article_info;
      console.log(lJSONObject_DataSet);

      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status == "success") {
            _this.tableData.splice(index, 1);
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    //所有上传的预包装商品
    // getList() {
    //   const _this = this;
    //   $.ajax({
    //     // headers: requestHeaders(),
    //     url: "https://service.kdddy.cn/donghuiForRequest/Purchase/GetAll",
    //     type: "get",
    //     data: {
    //       pageSize: 15,
    //       pageNumber: 1,
    //       id: "",
    //     },
    //     success: function (Result) {
    //       console.log(Result);
    //       _this.tableData = Result.Data;
    //       _this.total = Result.total;
    //     },
    //     complete: function (XMLHttpRequest) {
    //       requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
    //     },
    //     dataType: "json",
    //   });
    // },

    onSerach() {
      //查询方法
      this.form.PaginationNumber = 1;
      // this.getList(this.form);
    },
    examine() {
      //审核
      window.location.href = "./examine.html";
    },
    log() {
      window.location.href = "./log.html";
    },
    Add() {
      window.location.href = "./add.html";
    },
    Show(Article_SerialNumber) {
      this.Article_SerialNumber = Article_SerialNumber;
      this.dialogVisible = true;
    },
    // handleSizeChange(val) {
    //   this.form.PaginationNumber = 1;
    //   this.form.RowAmount = val;
    //   this.getList(this.form);
    // },
    // handleCurrentChange(val) {
    //   this.form.PaginationNumber = val;
    //   this.getList(this.form);
    // },
  },
});
